<?php
/**
 * @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
 * @license https://opensource.org/licenses/GPL-2.0
 * @link https://www.koogua.com
 */

namespace App\Repos;

use App\Models\CourseCategory as CourseCategoryModel;
use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Resultset;
use Phalcon\Mvc\Model\ResultsetInterface;

class CourseAgencies extends Repository
{

    /**
     * @param int $courseId
     * @param int $agencyId
     * @return \App\Models\CourseAgencies|Model|bool
     */
    public function findCourseAgencies($courseId, $agencyId)
    {
        return \App\Models\CourseAgencies::findFirst([
            'conditions' => 'course_id = :course_id: AND agency_id = :category_id:',
            'bind'       => ['course_id' => $courseId, 'category_id' => $agencyId],
        ]);
    }

    /**
     * @param array $agencyIds
     * @return ResultsetInterface|Resultset|CourseCategoryModel[]
     */
    public function findByAgencyIds($agencyIds)
    {
        return \App\Models\CourseAgencies::query()
            ->inWhere('agency_id', $agencyIds)
            ->execute();
    }

    /**
     * @param array $courseId
     * @return ResultsetInterface|Resultset|CourseCategoryModel[]
     */
    public function findByCourseIds($courseId)
    {
        return \App\Models\CourseAgencies::query()
            ->inWhere('course_id', $courseId)
            ->execute();
    }

    /**
     * @param array $agencyId
     * @return ResultsetInterface|Resultset|CourseCategoryModel[]
     */
    public function findByAgencyId($agencyId)
    {
        return \App\Models\CourseAgencies::query()
            ->inWhere('agency_id', $agencyId)
            ->execute();
    }
}
